home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / minmax.cls < prev    next >
Text File  |  1997-06-14  |  7KB  |  222 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "CMinMax"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Option Explicit
  11.  
  12. Public Enum EErrorMinMax
  13.     eeBaseMinMax = 13120    ' CMinMax
  14. End Enum
  15.  
  16. Implements ISubclass
  17.  
  18. Private tx As Long, ty As Long
  19. Private emr As EMsgResponse
  20. Private mmi As MINMAXINFO
  21. Private hWnd As Long
  22.  
  23. Private Sub Class_Initialize()
  24.     ' Do object access only once
  25.     tx = Screen.TwipsPerPixelX
  26.     ty = Screen.TwipsPerPixelY
  27.     ' Signal default
  28.     mmi.ptMaxSize.x = -1
  29.     mmi.ptMaxSize.y = -1
  30.     mmi.ptMaxPosition.x = -1
  31.     mmi.ptMaxPosition.y = -1
  32.     mmi.ptMinTrackSize.x = -1
  33.     mmi.ptMinTrackSize.y = -1
  34.     mmi.ptMaxTrackSize.x = -1
  35.     mmi.ptMaxTrackSize.y = -1
  36. End Sub
  37.  
  38. Private Sub Class_Terminate()
  39.     Destroy
  40. End Sub
  41.  
  42. Sub Create(hWndA As Long)
  43.     ' Get handle of system menu
  44.     hWnd = hWndA
  45.     AttachMessage Me, hWndA, WM_GETMINMAXINFO
  46. End Sub
  47.  
  48. Sub Destroy()
  49.     DetachMessage Me, hWnd, WM_GETMINMAXINFO
  50.     hWnd = hNull
  51. End Sub
  52.  
  53. ' Interface window procedure method
  54. Private Function ISubclass_WindowProc(ByVal hWnd As Long, _
  55.                                       ByVal iMsg As Long, _
  56.                                       ByVal wParam As Long, _
  57.                                       ByVal lParam As Long) As Long
  58.     Dim mmiT As MINMAXINFO
  59.     ' Copy parameter to local variable for processing
  60.     CopyMemory mmiT, ByVal lParam, LenB(mmiT)
  61.     ' Subclasser should never call unless it's our message
  62.     BugAssert iMsg = WM_GETMINMAXINFO
  63.     
  64.     ' Maximized width and height
  65.     With mmi.ptMaxSize
  66.         If .x <> -1 Then mmiT.ptMaxSize.x = .x
  67.         If .y <> -1 Then mmiT.ptMaxSize.y = .y
  68.     End With
  69.     
  70.     ' Maximized position of top left
  71.     With mmi.ptMaxPosition
  72.         If .x <> -1 Then mmiT.ptMaxPosition.x = .x
  73.         If .y <> -1 Then mmiT.ptMaxPosition.y = .y
  74.     End With
  75.     
  76.     ' Minimium width and height for sizing
  77.     With mmi.ptMinTrackSize
  78.         If .x <> -1 Then mmiT.ptMinTrackSize.x = .x
  79.         If .y <> -1 Then mmiT.ptMinTrackSize.y = .y
  80.     End With
  81.     
  82.     ' Maximium width and height for sizing
  83.     With mmi.ptMaxTrackSize
  84.         If .x <> -1 Then mmiT.ptMaxTrackSize.x = .x
  85.         If .y <> -1 Then mmiT.ptMaxTrackSize.y = .y
  86.     End With
  87.     
  88.     ' Copy modified results back to parameter
  89.     CopyMemory ByVal lParam, mmiT, LenB(mmiT)
  90.     
  91.     ' Don't pass back to original WindowProc
  92.     emr = emrConsume
  93. End Function
  94.  
  95. ' Interface properties
  96. Private Property Get ISubclass_MsgResponse() As EMsgResponse
  97.     ISubclass_MsgResponse = emr
  98. End Property
  99. Private Property Let ISubclass_MsgResponse(ByVal emrA As EMsgResponse)
  100.     emr = emrA
  101. End Property
  102.  
  103. Property Get MinWidth() As Long
  104.     MinWidth = mmi.ptMinTrackSize.x * tx
  105. End Property
  106. Property Let MinWidth(ByVal dxMinA As Long)
  107.     ' Must be positive, less than screen, and less than maximum
  108.     If dxMinA <= 0 Or dxMinA > Screen.Width Or _
  109.        dxMinA > (mmi.ptMaxTrackSize.x * tx) Then Exit Property
  110.     mmi.ptMinTrackSize.x = dxMinA / tx
  111. End Property
  112.  
  113. Property Get MinHeight() As Long
  114.     MinHeight = mmi.ptMinTrackSize.y * ty
  115. End Property
  116. Property Let MinHeight(ByVal dyMinA As Long)
  117.     ' Must be positive, less than screen, and less than maximum
  118.     If dyMinA <= 0 Or dyMinA > Screen.Height Or _
  119.        dyMinA > (mmi.ptMaxTrackSize.y * ty) Then Exit Property
  120.     mmi.ptMinTrackSize.y = dyMinA / ty
  121. End Property
  122.  
  123. Property Get MaxWidth() As Long
  124.     MaxWidth = mmi.ptMaxTrackSize.x * tx
  125. End Property
  126. Property Let MaxWidth(ByVal dxMaxA As Long)
  127. With mmi
  128.     ' Must be less than screen and greater than minimimum
  129.     If dxMaxA > Screen.Width Or dxMaxA < (.ptMinTrackSize.x * tx) Then
  130.         Exit Property
  131.     End If
  132.     .ptMaxTrackSize.x = dxMaxA / tx
  133.     ' Maximized size can't be greater than maximimum size
  134.     If .ptMaxTrackSize.x > .ptMaxSize.x Then .ptMaxSize.x = .ptMaxTrackSize.x
  135. End With
  136. End Property
  137.  
  138. Property Get MaxHeight() As Long
  139.     MaxHeight = mmi.ptMaxTrackSize.y * ty
  140. End Property
  141. Property Let MaxHeight(ByVal dyMaxA As Long)
  142. With mmi
  143.     ' Must be less than screen and greater than minimimum
  144.     If dyMaxA > Screen.Width Or dyMaxA < (.ptMinTrackSize.y * ty) Then
  145.         Exit Property
  146.     End If
  147.     .ptMaxTrackSize.y = dyMaxA / ty
  148.     ' Maximized size can't be greater than maximimum size
  149.     If .ptMaxTrackSize.y > .ptMaxSize.y Then .ptMaxSize.y = .ptMaxTrackSize.y
  150. End With
  151. End Property
  152.  
  153. Property Get MaximizedWidth() As Long
  154.     MaximizedWidth = mmi.ptMaxSize.x * tx
  155. End Property
  156. Property Let MaximizedWidth(ByVal dxMaximizedA As Long)
  157. With mmi
  158.     ' Must be less than screen and greater than minimimum
  159.     If dxMaximizedA > Screen.Width Or _
  160.        dxMaximizedA < (.ptMinTrackSize.x * tx) Then Exit Property
  161.     .ptMaxSize.x = dxMaximizedA / tx
  162.     ' Maximized size can't be greater than maximimum size
  163.     If .ptMaxSize.x > .ptMaxTrackSize.x Then .ptMaxTrackSize.x = .ptMaxSize.x
  164. End With
  165. End Property
  166.  
  167. Property Get MaximizedHeight() As Long
  168.     MaximizedHeight = mmi.ptMaxSize.y * ty
  169. End Property
  170. Property Let MaximizedHeight(ByVal dyMaximizedA As Long)
  171. With mmi
  172.     ' Must be less than screen and greater than minimimum
  173.     If dyMaximizedA > Screen.Height Or _
  174.        dyMaximizedA < (.ptMinTrackSize.y * ty) Then Exit Property
  175.     .ptMaxSize.y = dyMaximizedA / ty
  176.     ' Maximized size can't be greater than maximimum size
  177.     If .ptMaxSize.y > .ptMaxTrackSize.y Then .ptMaxTrackSize.y = .ptMaxSize.y
  178. End With
  179. End Property
  180.  
  181. Property Get MaximizedLeft() As Long
  182.     MaximizedLeft = mmi.ptMaxPosition.x * tx
  183. End Property
  184. Property Let MaximizedLeft(ByVal xMaximizedA As Long)
  185.     ' Must be positive and less than screen (but we won't enforce on
  186.     ' screen because we don't know property assignment order)
  187.     If xMaximizedA < 0 Or xMaximizedA >= Screen.Width Then Exit Property
  188.     mmi.ptMaxPosition.x = xMaximizedA / tx
  189. End Property
  190.  
  191. Property Get MaximizedTop() As Long
  192.     MaximizedTop = mmi.ptMaxPosition.y * ty
  193. End Property
  194. Property Let MaximizedTop(ByVal yMaximizedA As Long)
  195.     ' Must be positive and less than screen (but we won't enforce on
  196.     ' screen because we don't know property assignment order)
  197.     If yMaximizedA < 0 Or yMaximizedA >= Screen.Height Then Exit Property
  198.     mmi.ptMaxPosition.y = yMaximizedA / ty
  199. End Property
  200. '
  201.  
  202. #If fComponent = 0 Then
  203. Private Sub ErrRaise(e As Long)
  204.     Dim sText As String, sSource As String
  205.     If e > 1000 Then
  206.         sSource = App.ExeName & ".MinMax"
  207.         Select Case e
  208.         Case eeBaseMinMax
  209.             BugAssert True
  210.        ' Case ee...
  211.        '     Add additional errors
  212.         End Select
  213.         Err.Raise COMError(e), sSource, sText
  214.     Else
  215.         ' Raise standard Visual Basic error
  216.         sSource = App.ExeName & ".VBError"
  217.         Err.Raise e, sSource
  218.     End If
  219. End Sub
  220. #End If
  221.  
  222.